package com.zyj.test.month2.day1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Yijia Zhang
 * @create 2024-11-20 21:55
 */
public class Code0001 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        int idx = 0;
        for (int num : nums) {
            int aim = target - num;
            if (map.containsKey(aim)) {
                return new int[] {map.get(aim), idx};
            }
            map.put(num, idx);
            idx++;
        }
        return new int[0];
    }
}
